//
//  ImmediateViewController.m
//  iPhone SRV
//
//  Created by Nick Kitchener on 06/07/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "ImmediateViewController.h"

// Layers:
// - drive feed back when activated 
// - transparent touch control view
// - camera view (UART0 and if SVS and in landscape UART1)
// == window

// CameraView sizes
// Portrait: UART0 320x372
// Landscape Mono: UART0 240x212
// Landscape SVS: UART0 240x212 | UART1 240x212
// 

@implementation ImmediateViewController
@synthesize cameraViewUART0, cameraViewUART1, joypad;

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
		cameraViewUART0 = [ [[CameraView alloc] retain] initWithFrame:[self.view frame]];
		cameraViewUART1 = [ [[CameraView alloc] retain] initWithFrame:[self.view frame]];
		joypad = [ [[JoypadTouchControlView alloc] retain] initWithFrame:[self.view frame]];
		[self.view addSubview:cameraViewUART0];
		[self.view addSubview:joypad];
    }
    return self;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	
	return YES;
}

// update for current orientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
	NSLog(@"reorientating..");
	if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ) {
		// landscape
		// rebuild views to sit in correct locations.
		[cameraViewUART0 setFrame:CGRectMake(0,0,240,300)];
		[cameraViewUART1 setFrame:CGRectMake(240,0,240,300)];
		[self.view addSubview:cameraViewUART1];
	} else {
		// portrait
		[cameraViewUART0 setFrame:CGRectMake(0,0,320,372)];
		[cameraViewUART1 removeFromSuperview];
	}
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated {
	[cameraViewUART0 viewWillAppear];
	[cameraViewUART1 viewWillAppear];	
}

- (void)viewWillDisappear:(BOOL)animated {
	[cameraViewUART0 viewWillDisappear];
	[cameraViewUART1 viewWillDisappear];	
}

@end
